// map
// 返回一个新的数组,新数组的值是fn函数处理后的
const map = function (array, fn) {
    let result = [];
    for (let value of array) {
        result.push(fn(value));
    }
    return result;
};
let arr = [1, 2, 3, 4];
arr = map(arr, (item) => item * item);
console.log(arr);

// every
// 检测指定的条件是否全部匹配, 有一个不满足就返回false
const every = function (array, fn) {
    let result = true;
    for (let value of array) {
        result = fn(value);
        if (!result) {
            break;
        }
    }
    return result;
};
let arr2 = [5, 3, 6, 7, 9, 11];
let r = every(arr2, (item) => item > 6);
console.log(r);

// some
// 检测指定的条件是否有匹配的,只要有一个匹配的就返回true
const some = function (array, fn) {
    let result = false;
    for (let value of array) {
        result = fn(value);
        if (result) {
            break;
        }
    }
    return result;
};

let arr3 = [3, 4, 5, 6, 7, 8, 9, 0];
let r2 = some(arr3, (item) => item === 2);
console.log(r2);
